package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.RequestManager;
import com.isunland.managesystem.common.VolleyResponse;
import com.isunland.managesystem.entity.CompanyForumTopic;
import com.isunland.managesystem.entity.CompanyForumTopic.actualObject;
import com.isunland.managesystem.entity.CompanyForumType;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.SuccessMessage;
import com.isunland.managesystem.utils.FileNetWorkUtil;
import com.isunland.managesystem.utils.FileUtil;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.MyUtils;
import com.isunland.managesystem.utils.ToastUtil;
import com.loopj.android.http.AsyncHttpResponseHandler;
import java.util.HashMap;
import java.util.UUID;
import org.apache.http.Header;
import org.json.JSONException;

/**
 * 话题发布
 *
 * @author wu
 */
@SuppressWarnings("deprecation") public class CompanyForumTopicPublishFragment extends Fragment
    implements OnClickListener {

  public static final String EXTRA_VALUE = "com.isunland.managesystem.ui.EXTRA_VALUE";
  private static final int REQUEST_PICTUREA = 1;
  private static final int REQUEST_PICTUREB = 2;
  private static final int REQUEST_PICTUREC = 3;
  private static final int REQUEST_PICTURED = 4;
  public static final String REQUEST_EDIT = "com.isunland.managesystem.ui.REQUEST_EDIT";
  public static final String EXTRA_EDIT_TOPIC = "com.isunland.managesystem.ui..REQUEST_EDIT";
  private static final int CHOOSE_FILE = 0;
  private static final int REQUEST_CHECKMANS = 2;
  CompanyForumTopic.actualObject mTopicDetail;
  private EditText mTopicName;// 话题的名字
  private EditText mTopicContent;// 话题的内容

  private ImageView mIvPictureAForum;// 图片A
  private ImageView mIvPictureBForum;// 图片B
  private ImageView mIvPictureCForum;// 图片C
  private ImageView mIvPictureDForum;// 图片D
  private String mPicturePathA;// 图片D
  private String mPicturePathB;// 图片D
  private String mPicturePathC;// 图片D
  private String mPicturePathD;// 图片D

  private TextView mTvFileForum;// 附件
  private CheckBox mIsAnonymityCb;// 是否匿名
  private CheckBox mCheckManSetting;// 是否选择查看人,为空时全部.
  private BaseVolleyActivity mActivity;
  private CompanyForumType mTopicType;
  //private String mPicturePath = "";// 图片路径
  private String mFilePath;// 附件路径
  private String mTopicId;// 话题id
  private String mTopicTitle;// 话题标题
  private String mTopicContents;// 话题详情
  private String mTopicKindCode;// 话题类别编码
  private String mTopicKindName;// 话题类别名称
  private String mTopicFile;// 附件
  private String mTopicEdit;
  private String mName;// 返回的附件名
  private String mChoseFileName;
  private String mCharge;
  private String mChargeJobNo;
  private CurrentUser mCurrentUser;
  //private HashMap<String, String> mType;// 类型

  /**
   * 传递数据
   */
  public static Fragment newInstance(CompanyForumType type, actualObject topicContent,
      String topicEdit) {
    Bundle bundle = new Bundle();
    bundle.putSerializable(CompanyForumListFragment.EXTRA_FORUM_TYPE, type);
    bundle.putSerializable(EXTRA_VALUE, topicContent);
    bundle.putString(REQUEST_EDIT, topicEdit);
    CompanyForumTopicPublishFragment fragment = new CompanyForumTopicPublishFragment();
    fragment.setArguments(bundle);
    return fragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    mActivity = (BaseVolleyActivity) getActivity();
    if (NavUtils.getParentActivityName(getActivity()) != null) {
      if (mActivity.getSupportActionBar() != null) {
        mActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
    }
    if (mActivity.getSupportActionBar() != null) {
      mActivity.getSupportActionBar().setTitle(R.string.publishTopic);
    }

    mTopicType = (CompanyForumType) getArguments().getSerializable(
        CompanyForumListFragment.EXTRA_FORUM_TYPE);
    mCurrentUser = CurrentUser.newInstance(getActivity());
    mTopicDetail = (actualObject) getArguments().getSerializable(EXTRA_VALUE);
    if (mTopicDetail != null) {
      mTopicId = mTopicDetail.getId();
      mTopicTitle = mTopicDetail.getTopicTitle();
      mTopicContents = mTopicDetail.getTopicContents();
      mTopicKindCode = mTopicDetail.getTopicKindCode();
      mTopicKindName = mTopicDetail.getTopicKindName();
      mTopicFile = mTopicDetail.getTopicFile();
      mChargeJobNo = mTopicDetail.getLimitPersonal();
      mCharge = mTopicDetail.getLimitPersonalName();
      mPicturePathA = mTopicDetail.getTopicPicA();
      mPicturePathB = mTopicDetail.getTopicPicB();
      mPicturePathC = mTopicDetail.getTopicPicC();
      mPicturePathD = mTopicDetail.getTopicPicD();
    }
    LogUtil.i("mTopicKindCode=====" + mTopicKindCode);
    LogUtil.i("mTopicKindName=====" + mTopicKindName);
    LogUtil.i("mTopicFile=====" + mTopicFile);
    mTopicEdit = getArguments().getString(REQUEST_EDIT);

    // 初始化类型。
    //initType();
    super.onCreate(savedInstanceState);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_forum_publish_topic, container, false);
    mTopicName = (EditText) view.findViewById(R.id.et_topicName);
    mTopicContent = (EditText) view.findViewById(R.id.et_topicContent);
    mIvPictureAForum = (ImageView) view.findViewById(R.id.iv_pictureA_forumPublish);
    mIvPictureBForum = (ImageView) view.findViewById(R.id.iv_pictureB_forumPublish);
    mIvPictureCForum = (ImageView) view.findViewById(R.id.iv_pictureC_forumPublish);
    mIvPictureDForum = (ImageView) view.findViewById(R.id.iv_pictureD_forumPublish);
    mTvFileForum = (TextView) view.findViewById(R.id.tv_file_forum);
    mIsAnonymityCb = (CheckBox) view.findViewById(R.id.cb_is_annoymity);
    mCheckManSetting = (CheckBox) view.findViewById(R.id.cb_checkManSetting);
    if ((!TextUtils.isEmpty(mCharge)) && (!TextUtils.isEmpty(mChargeJobNo))) {
      //限制了查看人员.勾选限制查看.
      mCheckManSetting.setChecked(true);
    }

    mCheckManSetting.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        LogUtil.i("isChecked=" + isChecked);
        if (isChecked) {
          Intent intent = new Intent(getActivity(), SearchPersonMultipleActicity.class);
          intent.putExtra(SearchPersonMultipleFragment.EXTRA_FROM,
              SearchPersonMultipleFragment.VALUE_COMMON);
          //intent.putExtra(SearchPersonMultipleFragment.EXTRA_NAMES, SearchPersonMultipleFragment.VALUE_COMMON);
          intent.putExtra(SearchPersonMultipleFragment.EXTRA_JOB, mChargeJobNo);
          startActivityForResult(intent, REQUEST_CHECKMANS);
        }
      }
    });
    LinearLayout mIvAddFileForum = (LinearLayout) view.findViewById(R.id.iv_addFile_forum);
    if (EXTRA_EDIT_TOPIC.equalsIgnoreCase(mTopicEdit)) {
      if (mActivity.getSupportActionBar() != null) {

        mActivity.getSupportActionBar().setTitle(R.string.topicPublishEdit);
      }
      //            mIsAnonymityCb.setVisibility(View.GONE);
      mTopicName.setText(mTopicTitle);
      mTopicContent.setText(mTopicContents);
      if (mTopicFile != null) {
        mName = mTopicFile.substring(mTopicFile.lastIndexOf("/") + 1, mTopicFile.length());
        mTvFileForum.setText(mName);
      }
    }
    volleyPostGetPic(mPicturePathA, mIvPictureAForum);
    volleyPostGetPic(mPicturePathB, mIvPictureBForum);
    volleyPostGetPic(mPicturePathC, mIvPictureCForum);
    volleyPostGetPic(mPicturePathD, mIvPictureDForum);
    mIvAddFileForum.setOnClickListener(this);
    mIvPictureAForum.setOnClickListener(this);
    mIvPictureBForum.setOnClickListener(this);
    mIvPictureCForum.setOnClickListener(this);
    mIvPictureDForum.setOnClickListener(this);
    return view;
  }

  private void volleyPostGetPic(String pictureUrl, ImageView imageView) {
    ImageLoader mImageLoader = RequestManager.getImageLoader();
    if (!TextUtils.isEmpty(pictureUrl)) {
      imageView.setVisibility(View.VISIBLE);
      String urlImage = ApiConst.getDownLoadUrlByGet(pictureUrl);
      ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, // 控件名
          0, 0); // 默认图片
      mImageLoader.get(urlImage, listener);
    }
  }

  /**
   * 添加发布按钮
   */
  @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_forum_reply, menu);
    super.onCreateOptionsMenu(menu, inflater);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      // 响应返回按钮
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        break;

      // 响应发布按钮
      case R.id.menu_item_reply:
        contentExamineSave();
        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  protected void contentExamineSave() {
    boolean isEmpty = MyUtils.isEmptyText(mTopicName) || MyUtils.isEmptyText(mTopicContent);
    if (isEmpty) {
      Toast.makeText(getActivity(), R.string.notComplete, Toast.LENGTH_SHORT).show();
      return;
    }

    if (EXTRA_EDIT_TOPIC.equalsIgnoreCase(mTopicEdit)) {
      if (mChoseFileName != null) {
        if (mChoseFileName.equalsIgnoreCase(mName)) {
          Toast.makeText(getActivity(), R.string.fileExist, Toast.LENGTH_SHORT).show();
          return;
        }
      }
    }

    volleyPostSave();// 发布内容
  }

  //private void initType() {
  //
  //	String news = getActivity().getResources().getString(R.string.companyNews);
  //	String compSummarize = getActivity().getResources().getString(R.string.workSummarize);
  //	String depSummarize = getActivity().getResources().getString(R.string.departmentSummarize);
  //	String perSummarize = getActivity().getResources().getString(R.string.personalSummarize);
  //	String workSuggestion = getActivity().getResources().getString(R.string.workSuggestion);
  //	String perThought = getActivity().getResources().getString(R.string.personalThoughts);
  //	String others = getActivity().getResources().getString(R.string.others);
  //
  //	mType = new HashMap<String, String>();
  //	mType.put("01", news);
  //	mType.put("02", compSummarize);
  //	mType.put("03", depSummarize);
  //	mType.put("04", perSummarize);
  //	mType.put("05", workSuggestion);
  //	mType.put("06", perThought);
  //	mType.put("07", others);
  //}

  private void volleyPostSave() {
    MyUtils.showDialogLoading(getActivity());
    String url = ApiConst.getAbsoluteUrl(ApiConst.ULR_FORUM_PUBLISH);
    HashMap<String, String> params = new HashMap<>();
    String topicTitle = mTopicName.getText().toString();
    String topicContentStr = mTopicContent.getText().toString();
    //修改时候的参数是通过整个对象转为json的方式传递的.
    if (EXTRA_EDIT_TOPIC.equalsIgnoreCase(mTopicEdit)) {
      mTopicDetail.setTopicContents(topicContentStr);
      mTopicDetail.setTopicTitle(topicTitle);
      mTopicDetail.setId(mTopicId);
      mTopicDetail.setTopicKindCode(mTopicKindCode);
      mTopicDetail.setTopicKindName(mTopicKindName);
      if (mIsAnonymityCb.isChecked()) {
        mTopicDetail.setIfDisPlay("T");
      } else {
        mTopicDetail.setIfDisPlay("F");
      }

      //如果选中了查看人员,
      if (mCheckManSetting.isChecked()) {
        if (mCharge != null && mChargeJobNo != null) {
          mTopicDetail.setLimitPersonalName(mCharge);
          mTopicDetail.setLimitPersonal(mChargeJobNo);
        }
      } else {
        //如果没有勾选,就是全部,传""
        mTopicDetail.setLimitPersonalName("");
        mTopicDetail.setLimitPersonal("");
      }

      String jsonStr = new Gson().toJson(mTopicDetail);
      params = MyUtils.toHashMap(jsonStr);
    } else {
      //新建的时候通过key-value方式传递,与修改不同.
      mTopicId = UUID.randomUUID().toString();
      params.put("mainId", mTopicId);
      params.put("dataStatus", "new");
      params.put("topicKindCode", mTopicType.getCustomAttrs());
      params.put("topicKindName", mTopicType.getName());
      params.put("topicTitle", topicTitle);
      params.put("topicContents", topicContentStr);
      if (mIsAnonymityCb.isChecked()) {
        params.put("ifDisPlay", "T");
      } else {
        params.put("ifDisPlay", "F");
      }
      //如果选中了查看人员,
      if (mCheckManSetting.isChecked()) {
        if (mCharge != null && mChargeJobNo != null) {
          params.put("limitPersonalName", mCharge);
          params.put("limitPersonal", mChargeJobNo);
        }
      } else {
        //如果没有勾选,就是全部,传""
        params.put("limitPersonalName", "");
        params.put("limitPersonal", "");
      }
    }

    LogUtil.i("Saveparams=" + params);

    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        try {
          LogUtil.i("response=" + arg0);
          // MyUtils.dismissDialog();
          SuccessMessage success = new Gson().fromJson(arg0, SuccessMessage.class);
          if (null == success || null == success.getResult()) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          String successType = success.getResult();
          if (successType.equals("0")) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          if (successType.equals("1")) {
            // Toast.makeText(getActivity(),
            // R.string.success_operation,
            // Toast.LENGTH_SHORT).show();
            if (mFilePath != null) {
              // 用户选择了附件，可能为添加附件或修改附件。
              volleyPostSaveFile("topicFile", mFilePath);
            }
            if (mPicturePathA != null) {
              // 用户选择了附件，可能为添加附件或修改附件。
              volleyPostSaveFile("topicPicA", mPicturePathA);
            }
            if (mPicturePathB != null) {
              // 用户选择了附件，可能为添加附件或修改附件。
              volleyPostSaveFile("topicPicB", mPicturePathB);
            }
            if (mPicturePathC != null) {
              // 用户选择了附件，可能为添加附件或修改附件。
              volleyPostSaveFile("topicPicC", mPicturePathC);
            }
            if (mPicturePathD != null) {
              // 用户选择了附件，可能为添加附件或修改附件。
              volleyPostSaveFile("topicPicD", mPicturePathD);
            }

            //                        else {
            //if (EXTRA_EDIT_TOPIC.equalsIgnoreCase(mTopicEdit)) {
            //	Intent intent = new Intent(getActivity(), CompanyForumListActivity.class);
            //	intent.putExtra(CompanyForumListFragment.EXTRA_EDIT_TYPE, mTopicKindCode);
            //	startActivityForResult(intent, CompanyForumListFragment.REQUEST_TOPIC_EDIT);
            //	getActivity().finish();
            //} else {
            getActivity().setResult(Activity.RESULT_OK);
            getActivity().finish();
            //}
            //                        }
          }
        } catch (JsonSyntaxException e) {
          e.printStackTrace();
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        LogUtil.e("arg0===" + arg0);
      }
    });
  }

  /**
   * 附件上传
   */
  private void volleyPostSaveFile(String fieldName, String path) {
    String url = ApiConst.URL_TOPIC_FILEUPLOAD;
    HashMap<String, String> params = new HashMap<>();

    //        params.put("curtabName", "o_enterpriseforum_main");
    //        params.put("curid", mTopicId);

    params.put("fieldName", fieldName);
        /*生成缩略图*/
    new FileNetWorkUtil(getActivity()).upLoadFile(path, url, params, "o_enterpriseforum_main",
        mTopicId, new AsyncHttpResponseHandler() {
          //        new FileNetWorkUtil(getActivity()).upLoadFile(path, url, params, new AsyncHttpResponseHandler() {

          @Override public void onSuccess(int arg0, Header[] arg1, byte[] response) {
            MyUtils.dismissDialog();
            SuccessMessage message;
            try {
              message = new Gson().fromJson(new String(response), SuccessMessage.class);
              String result = message.getResult();
              LogUtil.i(new String(response));
              if (SuccessMessage.SUCCESS.equals(result)) {
                ToastUtil.show(R.string.fileSuccess);
                //if (EXTRA_EDIT_TOPIC.equalsIgnoreCase(mTopicEdit)) {
                //	Intent intent = new Intent(getActivity(), CompanyForumListActivity.class);
                //	intent.putExtra(CompanyForumListFragment.EXTRA_EDIT_TYPE, mTopicKindCode);
                //	startActivityForResult(intent, CompanyForumListFragment.REQUEST_TOPIC_FILE_EDIT);
                //	getActivity().finish();
                //} else {
                //                        getActivity().setResult(Activity.RESULT_OK);
                //                        getActivity().finish();
                //}
              }
              if (SuccessMessage.FAILURE.equals(result)) {
                ToastUtil.show(R.string.fileFail);
              }
            } catch (Exception e) {
              LogUtil.e("fileUploadError", e);
              ToastUtil.show(R.string.fileFail);
            }
            LogUtil.i("response=" + new String(response));
          }

          @Override
          public void onFailure(int arg0, Header[] arg1, byte[] errorResponse, Throwable arg3) {
            MyUtils.dismissDialog();
            ToastUtil.show(R.string.fileUploadFailure);
            LogUtil.i("onFailureresponse=" + new String(errorResponse));
          }
        }, true);
  }

  /**
   * 处理点击事件
   */
  @Override public void onClick(View v) {
    switch (v.getId()) {

      // 添加附件
      case R.id.iv_addFile_forum:
        chooseFileDialog();
        break;

      // 图片A
      case R.id.iv_pictureA_forumPublish:
        if (isPictureIfExist(mIvPictureAForum)) {
          choosePictureDialogA(REQUEST_PICTUREA);
        }
        break;

      // 图片B
      case R.id.iv_pictureB_forumPublish:
        if (isPictureIfExist(mIvPictureBForum)) {
          choosePictureDialogA(REQUEST_PICTUREB);
        }
        break;

      // 图片C
      case R.id.iv_pictureC_forumPublish:
        if (isPictureIfExist(mIvPictureCForum)) {
          choosePictureDialogA(REQUEST_PICTUREC);
        }
        break;

      // 图片D
      case R.id.iv_pictureD_forumPublish:
        if (isPictureIfExist(mIvPictureDForum)) {
          choosePictureDialogA(REQUEST_PICTURED);
        }
        break;

      default:
        break;
    }
  }

  /**
   * 判断图片是否为空
   *
   * @param iv ImageView空间
   * @return 返回boolean值，如果不为空提示，返回false，如果为空返回true
   */
  public boolean isPictureIfExist(final ImageView iv) {
    if (iv.getDrawable() != null) {
      AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
      dialog.setTitle(R.string.restart_title);
      dialog.setMessage(R.string.ifChangePicture);
      dialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

        @Override public void onClick(DialogInterface dialog, int which) {
          // 设置为空
          iv.setImageDrawable(null);
          iv.setBackgroundResource(R.drawable.add_photo);
        }
      });
      dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override public void onClick(DialogInterface dialog, int which) {
          dialog.dismiss();
        }
      });

      dialog.create().show();
      return false;
    }
    return true;
  }

  /**
   * 选择附件
   */
  private void chooseFileDialog() {
    DialogFragment dialog;
    FragmentManager fm = getActivity().getSupportFragmentManager();
    dialog = new CompanyForumTopicFileDialogFragment();
    dialog.setTargetFragment(CompanyForumTopicPublishFragment.this, CHOOSE_FILE);
    dialog.show(fm, "");
  }

  /**
   * 添加图片A选择拍照还是图库
   */
  public void choosePictureDialogA(int requestCode) {
    FragmentManager fm = getActivity().getSupportFragmentManager();
    DialogFragment dialog =
        ExtraUpLoadDialogFragment.newInstance("", ExtraUpLoadDialogFragment.TYPE_PHOTO);
    dialog.setTargetFragment(CompanyForumTopicPublishFragment.this, requestCode);
    dialog.show(fm, "");
  }

  /**
   * 处理返回按钮和返回的图片、附件
   */
  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
      return;
    }
    if (requestCode == REQUEST_CHECKMANS && data != null) {
      String names = data.getStringExtra(SearchPersonMultipleFragment.EXTRA_NAME);
      String jobNOs = data.getStringExtra(SearchPersonMultipleFragment.EXTRA_JOB);
      if ((!TextUtils.isEmpty(names)) && (!TextUtils.isEmpty(jobNOs))) {
        //如果都不为空,证明选择了人员.那么需要拼上当前登录人的jobNO和姓名.让他自己可见.
        if (!names.contains(mCurrentUser.getRealName())) {
          names = names + "," + mCurrentUser.getRealName();
        }
        if (!jobNOs.contains(mCurrentUser.getJobNumber())) {
          jobNOs = jobNOs + "," + mCurrentUser.getJobNumber();
        }

        mCharge = names;
        mChargeJobNo = jobNOs;
      }
    }

    String pictureResult;
    if (requestCode == REQUEST_PICTUREA && data != null) {
      // 获取返回的图片，并添加
      pictureResult = data.getStringExtra(ExtraUpLoadDialogFragment.EXTRA_RESULT);
      Bitmap bitmap = BitmapFactory.decodeFile(pictureResult);
      mPicturePathA = pictureResult;
      if (mPicturePathA != null) {
        mIvPictureAForum.setBackgroundColor(Color.WHITE);
        mIvPictureAForum.setImageBitmap(bitmap);
      }
    }
    if (requestCode == REQUEST_PICTUREB && data != null) {
      // 获取返回的图片，并添加
      pictureResult = data.getStringExtra(ExtraUpLoadDialogFragment.EXTRA_RESULT);
      Bitmap bitmap = BitmapFactory.decodeFile(pictureResult);
      mPicturePathB = pictureResult;
      if (mPicturePathB != null) {
        mIvPictureBForum.setBackgroundColor(Color.WHITE);
        mIvPictureBForum.setImageBitmap(bitmap);
      }
    }
    if (requestCode == REQUEST_PICTUREC && data != null) {
      // 获取返回的图片，并添加
      pictureResult = data.getStringExtra(ExtraUpLoadDialogFragment.EXTRA_RESULT);
      Bitmap bitmap = BitmapFactory.decodeFile(pictureResult);
      mPicturePathC = pictureResult;
      if (mPicturePathC != null) {
        mIvPictureCForum.setBackgroundColor(Color.WHITE);
        mIvPictureCForum.setImageBitmap(bitmap);
      }
    }
    if (requestCode == REQUEST_PICTURED && data != null) {
      // 获取返回的图片，并添加
      pictureResult = data.getStringExtra(ExtraUpLoadDialogFragment.EXTRA_RESULT);
      Bitmap bitmap = BitmapFactory.decodeFile(pictureResult);
      mPicturePathD = pictureResult;
      if (mPicturePathD != null) {
        mIvPictureDForum.setBackgroundColor(Color.WHITE);
        mIvPictureDForum.setImageBitmap(bitmap);
      }
    }

    if (requestCode == CHOOSE_FILE && data != null) {
      // 添加附件

      mFilePath = data.getStringExtra(CompanyForumTopicFileDialogFragment.EXTRA_RESULT);
      LogUtil.i("mPath=====" + mFilePath);
      if (mFilePath != null) {
        mChoseFileName = FileUtil.getFileNameByFilePath(mFilePath);
        mTvFileForum.setText(mChoseFileName);
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }
}
